﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using JEdwonTune.Common;

namespace JEdwonTune.Crud {
    public partial class FrmEditResource : FrmXmlNodeEditorBase {
        public FrmEditResource() {
            InitializeComponent();
        }

        private void FrmEditResource_Load(object sender, EventArgs e) {
            if (base.Node == null) {
                return;
            }
            if (base.Node.Name != "resource") {
                MessageBox.Show("编辑的节点不是property节点");
                this.Close();
                return;
            }
            if (base.Node.Attributes["name"] != null) {
                this.txtName.Text = base.Node.Attributes["name"].Value;
            }
            if (base.Node.Attributes["type"] != null) {
                this.txtType.Text = base.Node.Attributes["type"].Value;
            }
            if (base.Node.Attributes["value-field"] != null) {
                this.txtValField.Text = base.Node.Attributes["value-field"].Value;
            } else {
                this.txtValField.Text = "ID";
            }
            if (base.Node.Attributes["text-field"] != null) {
                this.txtTxtField.Text = base.Node.Attributes["text-field"].Value;
            } else {
                this.txtTxtField.Text = "Name";
            }
        }

        private void btnOK_Click(object sender, EventArgs e) {
            if (String.IsNullOrEmpty(this.txtName.Text.Trim())) {
                MessageBox.Show("请输入Name");
                return;
            }
            if (String.IsNullOrEmpty(this.txtType.Text.Trim())) {
                MessageBox.Show("请输入Type");
                return;
            }
            if (String.IsNullOrEmpty(this.txtValField.Text.Trim())) {
                MessageBox.Show("请输入value-field");
                return;
            }
            if (String.IsNullOrEmpty(this.txtTxtField.Text.Trim())) {
                MessageBox.Show("请输入text-field");
                return;
            }
            base.SetNodeAttrValue(base.Node,"name", this.txtName.Text.Trim());
            base.SetNodeAttrValue(base.Node,"type", this.txtType.Text.Trim());
            base.SetNodeAttrValue(base.Node,"value-field", this.txtValField.Text.Trim());
            base.SetNodeAttrValue(base.Node,"text-field", this.txtTxtField.Text.Trim());
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e) {
            this.Close();
        }
    }
}
